package call;

import java.sql.*;

public class CallStoreProcWithOutput {
	public static void main(String[] args) {
		try {
			// load driver
//			 Class.forName("net.sourceforge.jtds.jdbc.Driver");
			 Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			System.out.println("driver da duoc load ");
			// tao ket noi den CSDL
//			 Connection connection = DriverManager.getConnection(
//			 "jdbc:jtds:sqlserver://localhost:1433/test", "sa",
//			 "sa");
			Connection connection = DriverManager
					.getConnection("jdbc:sqlserver://localhost:1433;databaseName=test;user=sa;password=sa");
			System.out.println("Da ket noi duoc voi CSDL");
			
			// tao cau truy van
			String sql = "{call sumNumber(?, ?, ?)}";
			// thuc hien cau truy van
			CallableStatement call = connection.prepareCall(sql);
			
			call.setInt(1, 4);
			call.setInt(2, 6);
			call.registerOutParameter(3, java.sql.Types.INTEGER);
			
			//
			call.execute();
			
			System.out.println("gia tri output " + call.getInt(3));
			
		} catch (ClassNotFoundException ex) {
			ex.printStackTrace();
		} catch (SQLException ex) {
			ex.printStackTrace();
		}

	}
}
